package com.epam.web_project.bank.command;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import com.epam.web_project.bank.command.admin_commands.ApproveUserCommand;
import com.epam.web_project.bank.command.admin_commands.CreateAccountCommand;
import com.epam.web_project.bank.command.admin_commands.MarkUnapprovedAccountDeleted;
import com.epam.web_project.bank.command.admin_commands.MarkUnapprovedUserDeleted;
import com.epam.web_project.bank.command.admin_commands.MarkWorkingAccountDeletedCommand;
import com.epam.web_project.bank.command.admin_commands.PutMoneyCommand;
import com.epam.web_project.bank.command.admin_commands.UnblockAccountCommand;
import com.epam.web_project.bank.command.customer_commands.AnswerSecretQuestionCommand;
import com.epam.web_project.bank.command.customer_commands.BlockAccountCommand;
import com.epam.web_project.bank.command.customer_commands.CardRequestCommand;
import com.epam.web_project.bank.command.customer_commands.ChangePasswordCommand;
import com.epam.web_project.bank.command.customer_commands.CheckAccountBlockCommand;
import com.epam.web_project.bank.command.customer_commands.FindByLoginCommand;
import com.epam.web_project.bank.command.customer_commands.RegisterCommand;
import com.epam.web_project.bank.command.customer_commands.TransferCommand;
import com.epam.web_project.bank.command.show_commands.ShowAccountForm;
import com.epam.web_project.bank.command.show_commands.ShowAdminMainCommand;
import com.epam.web_project.bank.command.show_commands.ShowCardRequestCommand;
import com.epam.web_project.bank.command.show_commands.ShowHistoryCommand;
import com.epam.web_project.bank.command.show_commands.ShowMainCommand;
import com.epam.web_project.bank.command.show_commands.ShowPutMoneyForm;
import com.epam.web_project.bank.command.show_commands.ShowTransferCommand;
import com.epam.web_project.bank.command.show_commands.ShowUnapprovedCommand;
import com.epam.web_project.bank.command.show_commands.ShowUserInfoCommand;
import com.epam.web_project.bank.command.show_commands.ShowWorkingAccountsCommand;

public class CommandManager {
	private static CommandManager instance;
	private HashMap<String, Command> commands = new HashMap<String, Command>();

	private CommandManager() {
		commands.put("login", new LoginCommand());// anyone
		commands.put("register", new RegisterCommand());// anyone
		commands.put("recoverPass", new FindByLoginCommand());// anyone
		commands.put("answer", new AnswerSecretQuestionCommand());// tempCustomer
		commands.put("changePass", new ChangePasswordCommand());// tempCustomer
		commands.put("showMainCommand", new ShowMainCommand()); // customer
		commands.put("sendAccountId", new CheckAccountBlockCommand());// customer
		commands.put("transfer", new TransferCommand());// customer
		commands.put("showTransferCommand", new ShowTransferCommand());
		commands.put("block", new BlockAccountCommand());// customer
		commands.put("history", new ShowHistoryCommand());
		commands.put("showCardRequestCommand", new ShowCardRequestCommand());
		commands.put("cardRequest", new CardRequestCommand());// unapproved,customer
		commands.put("showUnapprovedCommand", new ShowUnapprovedCommand());// unapproved
		commands.put("showCardReq", new ShowCardRequestCommand());// unapproved,customer
		commands.put("showAdminMainCommand", new ShowAdminMainCommand());// admin
		commands.put("showAccForm", new ShowAccountForm());// admin
		commands.put("createAccount", new CreateAccountCommand());// admin
		commands.put("showUserInfo", new ShowUserInfoCommand());// admin
		commands.put("approveUser", new ApproveUserCommand());// admin
		commands.put("logout", new LogoutCommand()); // anyone
		commands.put("showWorkingAccountsCommand",
				new ShowWorkingAccountsCommand());// admin
		commands.put("unblock", new UnblockAccountCommand());// admin
		commands.put("showPutMoneyPage", new ShowPutMoneyForm());// admin
		commands.put("putMoney", new PutMoneyCommand()); // admin
		commands.put("markWorkingAccountDeleted",
				new MarkWorkingAccountDeletedCommand());// admin
		commands.put("markUnapprovedAccountDeleted",
				new MarkUnapprovedAccountDeleted());// admin
		commands.put("markUnapprovedUserDeleted",
				new MarkUnapprovedUserDeleted());//admin
		commands.put("onMain", new OnMainCommand());//anyone
	}

	public Command getCommand(HttpServletRequest request) {
		String action = request.getParameter("command");
		Command command = commands.get(action);
		if (command == null) {
			command = new NoCommand();
		}
		return command;
	}

	public static CommandManager getInstance() {
		if (instance == null) {
			instance = new CommandManager();
		}
		return instance;
	}
}
